package com.lf.controller;

import com.alibaba.fastjson.JSONObject;
import com.lf.constant.ConstantsValue;
import com.lf.entity.*;
import com.lf.enums.ErrorCodeEnum;
import com.lf.exception.ApiException;
import com.lf.jwt.SameUrlData;
import com.lf.jwt.TokenEntity;
import com.lf.jwt2admin.ManagerToken;
import com.lf.service.ServiceList;
import com.lf.swagger.ApiJsonObject;
import com.lf.swagger.ApiJsonProperty;
import com.lf.util.Asserts;
import io.jsonwebtoken.ExpiredJwtException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @program: 接口【管理台】
 * @description: 会员
 * @author: bite
 * @create:
 **/
@Slf4j
@Api(value = "admin", tags = "管理台")
@RestController
@RequestMapping("/admin")
public class AdminController  extends ServiceList {


    /**
     * 提现
     * @param jsonParam
     * @return
     */
    @SameUrlData
    @ManagerToken
    @RequestMapping(value = "/reDrawn", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]重新提现", response = String.class)
    public ResponseWrapper reDrawn(@ApiJsonObject(name = "reDrawnParams", value = {
            @ApiJsonProperty(key = "outTradeNo", value = "商户订单号")
    }) @RequestBody JSONObject jsonParam){
        try {
            redisLockRegistry.obtain(ConstantsValue.COLONY_DRAWN_LOCK).lock();
            ConstantsValue.DRAWN_LOCK.writeLock().lock();
            String outTradeNo = jsonParam.getString("outTradeNo");
            Asserts.notBlank(outTradeNo,"outTradeNo");
            return userService.reDrawn(outTradeNo);
        }catch (ApiException e){
            log.error(String.format("[管理台]重新提现失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]重新提现失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }finally {
            ConstantsValue.DRAWN_LOCK.writeLock().unlock();
            redisLockRegistry.obtain(ConstantsValue.COLONY_DRAWN_LOCK).unlock();
        }
    }



    /**
     * 更新审核认证状态
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/updateAuth", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]审核认证状态", response = String.class)
    public ResponseWrapper updateAuth(
            @ApiJsonObject(name = "updateAuthParams", value = {
                    @ApiJsonProperty(key = "authId", value = "记录id"),
                    @ApiJsonProperty(key = "status", value = "审核状态，1：审核通过，2：审核不通过"),
                    @ApiJsonProperty(key = "rname", value = "姓名"),
                    @ApiJsonProperty(key = "year", value = "年"),
                    @ApiJsonProperty(key = "mouth", value = "月"),
                    @ApiJsonProperty(key = "day", value = "日"),
                    @ApiJsonProperty(key = "idc", value = "身份证"),
                    @ApiJsonProperty(key = "nation", value = "民族"),
                    @ApiJsonProperty(key = "sex", value = "性别"),
                    @ApiJsonProperty(key = "addr", value = "地址"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer id = jsonParam.getInteger("authId");
            String status = jsonParam.getString("status");

            String rname = jsonParam.getString("rname");
            String year = jsonParam.getString("year");
            String mouth = jsonParam.getString("mouth");
            String day = jsonParam.getString("day");
            String idc = jsonParam.getString("idc");
            String nation = jsonParam.getString("nation");
            String sex = jsonParam.getString("sex");
            String addr = jsonParam.getString("addr");

            userService.updateAuth(id, status, rname,year,mouth,day,idc,nation,sex,addr);
            return ResponseWrapper.succeed("操作成功");
        } catch (ApiException e) {
            log.error(String.format("[管理台]审核认证状态失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]审核认证状态失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 认证申请列表
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/authList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]认证申请列表", response = String.class)
    public ResponseWrapper authList(
            @ApiJsonObject(name = "updateAuthParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "status", value = "状态"),
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");
            Integer status = jsonParam.getInteger("status");
            Asserts.notBlank(String.valueOf(status), "状态");

            return userService.authList(page, limit, status);

        } catch (ApiException e) {
            log.error(String.format("[管理台]获取认证申请列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取认证申请列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }


    /**
     * 查询用户列表
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/userList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]查询用户列表", response = String.class)
    public ResponseWrapper userList(
            @ApiJsonObject(name = "userListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");


            return userService.userList(page, limit);

        } catch (ApiException e) {
            log.error(String.format("[管理台]查询用户列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]查询用户列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 查询用户收益记录
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/userRevenueList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]查询用户收益记录", response = String.class)
    public ResponseWrapper userRevenueList(
            @ApiJsonObject(name = "userRevenueListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "userId", value = "用户id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");
            Integer userId = jsonParam.getInteger("userId");

            return userService.userRevenueList(page, limit, userId);

        } catch (ApiException e) {
            log.error(String.format("[管理台]查询用户收益记录失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]查查询用户收益记录失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 查询用户提现记录
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/userWithDrawnList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]查询用户提现记录", response = String.class)
    public ResponseWrapper userWithDrawnList(
            @ApiJsonObject(name = "userWithDrawnListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "userId", value = "用户id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");
            Integer userId = jsonParam.getInteger("userId");

            return userService.userWithDrawnList(page, limit, userId);

        } catch (ApiException e) {
            log.error(String.format("[管理台]查询用户提现记录失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]查询用户提现记录失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 禁止用户提现
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/noDrawn", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]禁止用户提现", response = String.class)
    public ResponseWrapper noDrawn(
            @ApiJsonObject(name = "noDrawnParams", value = {
                    @ApiJsonProperty(key = "userId", value = "用户id")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer userId = jsonParam.getInteger("userId");
            Asserts.checkUserId(userId,"用户ID");

            return userService.noDrawn(userId);

        } catch (ApiException e) {
            log.error(String.format("[管理台]禁止用户提现失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]禁止用户提现失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 关闭/开启核查收费
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/closeOrOpenPay", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]关闭核查收费", response = String.class)
    public ResponseWrapper closeOrOpenPay(
            @ApiJsonObject(name = "closeOrOpenPayParams", value = {})
            @RequestBody JSONObject jsonParam) {
        try {
            return userService.closeOrOpenPay();
        } catch (ApiException e) {
            log.error(String.format("[管理台]关闭核查收费失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]关闭核查收费失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 获取核查收费状态
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/getPayStatus", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取核查收费状态", response = String.class)
    public ResponseWrapper getPayStatus(
            @ApiJsonObject(name = "getPayStatusParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            return userService.getPayStatus();
        } catch (ApiException e) {
            log.error(String.format("[管理台]获取核查收费状态失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取核查收费状态失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }



    /**
     * 关闭/开启提现功能
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/closeOrOpenDrawnStatus", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]关闭/开启提现功能", response = String.class)
    public ResponseWrapper closeOrOpenDrawnStatus(
            @ApiJsonObject(name = "closeOrOpenDrawnStatusParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            return userService.closeOrOpenDrawnStatus();
        } catch (ApiException e) {
            log.error(String.format("[管理台]关闭/开启提现功能失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]关闭/开启提现功能失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 获取提现开关状态
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/getDrawnStatus", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取提现开关状态", response = String.class)
    public ResponseWrapper getDrawnStatus(
            @ApiJsonObject(name = "getDrawnStatusParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            return userService.getDrawnStatus();
        } catch (ApiException e) {
            log.error(String.format("[管理台]获取提现开关状态失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取提现开关状态失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 获取吐槽列表
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/reportList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取吐槽列表", response = String.class)
    public ResponseWrapper reportList(
            @ApiJsonObject(name = "reportListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "userName", value = "用户姓名"),
                    @ApiJsonProperty(key = "isReally", value = "是否审核通过")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");
            Integer isReally = jsonParam.getInteger("isReally");
            String userName = jsonParam.getString("userName");

            return userService.reportList(page,limit,isReally,userName);
        } catch (ApiException e) {
            log.error(String.format("[管理台]获取吐槽列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取吐槽列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 审核吐槽
     * @param jsonParam
     * @return
     */
//    @ManagerToken
    @RequestMapping(value = "/examineReport", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]审核吐槽", response = String.class)
    public ResponseWrapper examineReport(
            @ApiJsonObject(name = "examineReportParams", value = {
                    @ApiJsonProperty(key = "reportId", value = "ID"),
                    @ApiJsonProperty(key = "isReally", value = "是否审核通过")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer reportId = jsonParam.getInteger("reportId");
            Integer isReally = jsonParam.getInteger("isReally");

            return userService.examineReport(reportId,isReally);
        } catch (ApiException e) {
            log.error(String.format("[管理台]审核吐槽失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]审核吐槽失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }


    /**
     * 获取用户支付列表
     * outTradeNo
     * resultCode
     * errCode
     * attach
     * transactionId
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/payList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取用户支付列表", response = String.class)
    public ResponseWrapper payList(
            @ApiJsonObject(name = "payListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "outTradeNo", value = "商户订单号"),
                    @ApiJsonProperty(key = "resultCode", value = "业务结果码"),
                    @ApiJsonProperty(key = "errCode", value = "错误码"),
                    @ApiJsonProperty(key = "attach", value = "消费类型"),
                    @ApiJsonProperty(key = "transactionId", value = "微信支付订单号")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");
            String outTradeNo = jsonParam.getString("outTradeNo");
            String resultCode = jsonParam.getString("resultCode");
            String errCode = jsonParam.getString("errCode");
            Integer attach = jsonParam.getInteger("attach");
            String transactionId = jsonParam.getString("transactionId");

            return userService.payList(page,limit,resultCode,errCode,outTradeNo,attach,transactionId);
        } catch (ApiException e) {
            log.error(String.format("[管理台]获取用户支付列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取用户支付列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 获取企业支付列表
     * parterTradeNo
     * errCode
     * paymentNo
     * resultCode
     * reUserName
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/transferList", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]企业支付列表", response = String.class)
    public ResponseWrapper transferList(
            @ApiJsonObject(name = "transferListParams", value = {
                    @ApiJsonProperty(key = "page", value = "页码"),
                    @ApiJsonProperty(key = "limit", value = "行数"),
                    @ApiJsonProperty(key = "parterTradeNo", value = "商户订单号"),
                    @ApiJsonProperty(key = "errCode", value = "错误码"),
                    @ApiJsonProperty(key = "resultCode", value = "业务结果，SUCCESS/FAIL"),
                    @ApiJsonProperty(key = "paymentNo", value = "企业付款单号"),
                    @ApiJsonProperty(key = "reUserName", value = "收款人姓名")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer page = jsonParam.getInteger("page");
            Integer limit = jsonParam.getInteger("limit");
            String resultCode = jsonParam.getString("resultCode");
            String parterTradeNo = jsonParam.getString("parterTradeNo");
            String errCode = jsonParam.getString("errCode");
            String paymentNo = jsonParam.getString("paymentNo");
            String reUserName = jsonParam.getString("reUserName");

            return userService.transferList(page,limit,resultCode,parterTradeNo,errCode,paymentNo,reUserName);
        } catch (ApiException e) {
            log.error(String.format("[管理台]获取企业支付列表失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error(String.format("[管理台]获取企业支付列表失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    /**
     * 获取启动或关闭小程序审核助手
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/getCO", method = RequestMethod.POST)
    @ApiOperation(tags = "小程序接口", httpMethod = "POST", value = "[管理台]获取敏感功能配置", response = String.class)
    public ResponseWrapper getCO(@ApiJsonObject(name = "getCOParams", value = {}) @RequestBody JSONObject jsonParam){
        try {
            return userService.getCO();
        }catch (ApiException e){
            log.error(String.format("[管理台]获取启动或关闭小敏感功能失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]获取启动或关闭敏感功能失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }finally {
        }
    }


    /**
     * 启动或关闭敏感功能
     * @param jsonParam
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/closeOrOpen", method = RequestMethod.POST)
    @ApiOperation(tags = "小程序接口", httpMethod = "POST", value = "[管理台]启动或关闭敏感功能", response = String.class)
    public ResponseWrapper closeOrOpen(@ApiJsonObject(name = "closeOrOpenParams", value = {}) @RequestBody JSONObject jsonParam){
        try {
            return userService.closeOrOpen();
        }catch (ApiException e){
            log.error(String.format("[管理台]启动或关闭敏感功能失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]启动或关闭敏感功能失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }finally {
        }
    }

    @ManagerToken
    @RequestMapping(value = "/getAdminInfo", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取管理员信息", response = String.class)
    public ResponseWrapper getAdminInfo(
            @ApiJsonObject(name = "getAdminInfoParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            Integer id = jsonParam.getInteger("id");

            return customerService.getAdminInfo(id);
        }catch (ApiException e){
            log.error(String.format("[管理台]获取管理员信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]获取管理员信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }
    @ManagerToken
    @RequestMapping(value = "/updateAdmin", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]管理员信息更新", response = String.class)
    public ResponseWrapper updateAdmin(
            @ApiJsonObject(name = "updateAdminParams", value = {
                    @ApiJsonProperty(key = "account", value = "账号"),
                    @ApiJsonProperty(key = "fullName", value = "公司全名"),
                    @ApiJsonProperty(key = "legalName", value = "昵称"),
                    @ApiJsonProperty(key = "address", value = "公司地址"),
                    @ApiJsonProperty(key = "mobile", value = "联系手机/座机")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer id = jsonParam.getInteger("id");
            String fullName = jsonParam.getString("fullName");
            String legalName = jsonParam.getString("legalName");
            String address = jsonParam.getString("address");
            String mobile = jsonParam.getString("mobile");
            Asserts.checkMobile(mobile, "手机号");
            Asserts.notBlank(fullName,"公司名称");
            Asserts.notBlank(address,"公司地址");

            return customerService.updateAdmin(id,fullName,legalName,address,mobile);
        }catch (ApiException e){
            log.error(String.format("[管理台]管理员信息更新失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]管理员信息更新失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @ManagerToken
    @RequestMapping(value = "/updateAdminPass", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]管理员更换密码", response = String.class)
    public ResponseWrapper updateAdminPass(
            @ApiJsonObject(name = "updateAdminPassParams", value = {
                    @ApiJsonProperty(key = "oldPassword", value = "旧密码"),
                    @ApiJsonProperty(key = "newPassword", value = "新密码")
            }) @RequestBody JSONObject jsonParam) {
        try {
            Integer id = jsonParam.getInteger("id");
            String oldPassword = jsonParam.getString("oldPassword");
            String newPassword = jsonParam.getString("newPassword");
            Asserts.checkPsw(oldPassword,"旧密码");
            Asserts.checkPsw(newPassword,"新密码");

            return customerService.updateAdminPass(id,oldPassword,newPassword);
        }catch (ApiException e){
            log.error(String.format("[管理台]管理员更换密码失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]管理员更换密码失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }




    /**
     * 获取 总收益 总支出 已支出 未支出 平台用户数 平台代理商数 平台普通用户数
     * @param
     * @return
     */
    @ManagerToken
    @RequestMapping(value = "/getDatas", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取 总收益 总支出 已支出 未支出 平台用户数 平台代理商数 平台普通用户数", response = String.class)
    public ResponseWrapper getDatas(
            @ApiJsonObject(name = "getDatasParams", value = {}) @RequestBody JSONObject jsonParam){
        try {
            return userService.getDatas();
        }catch (ApiException e){
            log.error(String.format("[管理台]获取总收益/总支出/已支出/未支出/平台用户数/平台代理商数/平台普通用户数失败，参数:%s, 错误信息:%s", null, e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]获取总收益/总支出/已支出/未支出/平台用户数/平台代理商数/平台普通用户数失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }finally {
        }
    }

    @ManagerToken
    @RequestMapping(value = "/updateWeiXinData", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]更新微信配置信息", response = String.class)
    public ResponseWrapper updateWeiXinData(
            @ApiJsonObject(name = "updateWeiXinDataParams", value = {
                    @ApiJsonProperty(key = "WX_APPID", value = "WX_APPID"),
                    @ApiJsonProperty(key = "WX_SECRET", value = "WX_SECRET"),
                    @ApiJsonProperty(key = "WX_NOTIFY", value = "WX_NOTIFY"),
                    @ApiJsonProperty(key = "SECRET_ID", value = "SECRET_ID"),
                    @ApiJsonProperty(key = "SECRET_KEY", value = "SECRET_KEY"),
                    @ApiJsonProperty(key = "MCH_ID", value = "MCH_ID"),
                    @ApiJsonProperty(key = "MCH_KEY", value = "MCH_KEY")
            })  @RequestBody JSONObject jsonParam) {
        try {

            String WX_APPID = jsonParam.getString("WX_APPID");
            String WX_SECRET = jsonParam.getString("WX_SECRET");
            String WX_NOTIFY = jsonParam.getString("WX_NOTIFY");
            String SECRET_ID = jsonParam.getString("SECRET_ID");
            String SECRET_KEY = jsonParam.getString("SECRET_KEY");
            String MCH_ID = jsonParam.getString("MCH_ID");
            String MCH_KEY = jsonParam.getString("MCH_KEY");
            Asserts.notBlank("WX_APPID","WX_APPID");
            Asserts.notBlank("WX_SECRET","WX_SECRET");
            Asserts.notBlank("WX_NOTIFY","WX_NOTIFY");
            Asserts.notBlank("SECRET_ID","SECRET_ID");
            Asserts.notBlank("SECRET_KEY","SECRET_KEY");
            Asserts.notBlank("MCH_ID","MCH_ID");
            Asserts.notBlank("MCH_KEY","MCH_KEY");

            return sysService.updateWeiXinData(WX_APPID,WX_SECRET,WX_NOTIFY,SECRET_ID,SECRET_KEY,MCH_ID,MCH_KEY);
        }catch (ApiException e){
            log.error(String.format("[管理台]更新微信配置信息失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]更新微信配置信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }
    @ManagerToken
    @RequestMapping(value = "/getWeiXinData", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取微信配置信息", response = String.class)
    public ResponseWrapper getWeiXinData(
            @ApiJsonObject(name = "getWeiXinDataParams", value = {})   @RequestBody JSONObject jsonParam) {
        try {
            return sysService.getWeiXinData();
        }catch (ApiException e){
            log.error(String.format("[管理台]获取微信配置信息失败，参数:%s, 错误信息:%s", "token", e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]获取微信配置信息失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }


    @ManagerToken
    @RequestMapping(value = "/getLegalName", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]获取管理员昵称", response = String.class)
    public ResponseWrapper getLegalName(
            @ApiJsonObject(name = "getLegalNameParams", value = {})   @RequestBody JSONObject jsonParam) {
        try {
//            String id = this.checkUserToken(token);
            Integer id = jsonParam.getInteger("id");
            return customerService.getAdminInfo(id);
        }catch (ApiException e){
            log.error(String.format("[管理台]获取管理员昵称失败，参数:%s, 错误信息:%s", "token", e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]获取管理员昵称失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @ManagerToken
    @RequestMapping(value = "/getAuthority", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]权限菜单", response = String.class)
    public ResponseWrapper getAuthority(@ApiJsonObject(name = "getAuthorityParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            Integer id = jsonParam.getInteger("id");
            return customerService.getAuthority(id);
        }catch (ApiException e){
            log.error(String.format("[管理台]获取权限失败，参数:%s, 错误信息:%s", "jsonParam.toJSONString()", e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]获取权限失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }



    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]用户登录", response = String.class)
    public ResponseWrapper login(
            @ApiJsonObject(name = "loginParams", value = {
                    @ApiJsonProperty(key = "account", value = "账号"),
                    @ApiJsonProperty(key = "password", value = "密码")
            }) @RequestBody JSONObject jsonParam) {
        try {
            String account = jsonParam.getString("account");
            String password = jsonParam.getString("password");
            Asserts.checkAccount(account,"账号");
            Asserts.checkPsw(password,"密码");
            return customerService.login(account,password);
        }catch (ApiException e){
            log.error(String.format("[管理台]登录失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]登录失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/loginOut", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]用户登出", response = String.class)
    public ResponseWrapper loginOut(@ApiJsonObject(name = "loginOutParams", value = {}) @RequestBody JSONObject jsonParam) {
        try {
            Integer id = tokenAdmin.getToken(jsonParam.getString("token")).getUserId();
            return customerService.loginOut(id);
        }catch (ApiException e){
            log.error(String.format("[管理台]登出失败，参数:%s, 错误信息:%s", "token", e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]登出失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

    @RequestMapping(value = "/addManager", method = RequestMethod.POST)
    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[管理台]添加管理员", response = String.class)
    public ResponseWrapper addManager(
            @ApiJsonObject(name = "addManagerParams", value = {
                    @ApiJsonProperty(key = "account", value = "账号"),
                    @ApiJsonProperty(key = "password", value = "密码")
            }) @RequestBody JSONObject jsonParam) {
        try {
            String account = jsonParam.getString("account");
            String password = jsonParam.getString("password");
            Asserts.checkAccount(account,"账号");
            Asserts.checkPsw(password,"密码");

            return customerService.addManager(account,password);
        }catch (ApiException e){
            log.error(String.format("[管理台]添加管理员失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
            return ResponseWrapper.failed(e.getCode(), e.getMessage());
        }catch (Exception e){
            log.error(String.format("[管理台]添加管理员失败"), e);
            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
        }
    }

}
//

    /**
     * 用户参数绑定
     */
//    public String checkUserToken(String token) {
//        try {
//            // 进行jwt验证
//            TokenEntity entity = tokenAdmin.getToken(token);
//            ErrorCodeEnum errorCodeEnum = tokenAdmin.checkToken(entity);
//            if (ErrorCodeEnum.SC0 == errorCodeEnum) {
//                return String.valueOf(entity.getUserId());
//            } else {
//                throw new ApiException(errorCodeEnum);
//            }
//        } catch (ApiException e) {
//            throw e;
//        } catch (ExpiredJwtException ee) {
//            throw new ApiException(ErrorCodeEnum.TK1005);
//        } catch (Exception e) {
//            throw new ApiException(ErrorCodeEnum.TK1006);
//        }
//    }
//    @RequestMapping(value = "/takeBlack", method = RequestMethod.POST)
//    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]拉黑用户/拉白用户", response = List.class)
//    public ResponseWrapper takeBlack(
//            @ApiJsonObject(name = "takeBlackParams", value = {
//                    @ApiJsonProperty(key = "userId", value = "用户id")
//            }) @RequestBody JSONObject jsonParam) {
//        try {
//            Integer userId = jsonParam.getInteger("userId");
//            Asserts.naturalNumber(userId, "用户id");
//
//            userService.takeBlack(userId);
//            return ResponseWrapper.succeed();
//        } catch (ApiException e) {
//            log.error(String.format("[后台]拉黑用户/拉白用户失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
//            return ResponseWrapper.failed(e.getCode(), e.getMessage());
//        } catch (Exception e) {
//            log.error(String.format("[后台]拉黑用户/拉白用户失败"), e);
//            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
//        }
//    }

//
//    @RequestMapping(value = "/getAboutsUs", method = RequestMethod.POST)
//    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]获取关于我们", response = List.class)
//    public ResponseWrapper getAboutsUs(
//            @ApiJsonObject(name = "getAboutsUsParams", value = {
//            }) @RequestBody JSONObject jsonParam) {
//        try {
//            String s = userService.getAboutsUs();
//            return ResponseWrapper.succeed(s);
//        } catch (ApiException e) {
//            log.error(String.format("[后台]获取关于我们失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
//            return ResponseWrapper.failed(e.getCode(), e.getMessage());
//        } catch (Exception e) {
//            log.error(String.format("[后台]获取关于我们失败"), e);
//            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
//        }
//    }
//
//    @RequestMapping(value = "/setAboutsUs", method = RequestMethod.POST)
//    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[后台]设置关于我们", response = List.class)
//    public ResponseWrapper setAboutsUs(
//            @ApiJsonObject(name = "setAboutsUsParams", value = {
//                    @ApiJsonProperty(key = "aboutsUs", value = "关于我们")
//            }) @RequestBody JSONObject jsonParam) {
//        try {
//            String about = jsonParam.getString("aboutsUs");
//            Asserts.notBlank(about, "关于我们");
//
//            userService.setAboutsUs(about);
//            return ResponseWrapper.succeed();
//        } catch (ApiException e) {
//            log.error(String.format("[后台]设置关于我们失败，参数:%s, 错误信息:%s", jsonParam.toJSONString(), e.getMessage()));
//            return ResponseWrapper.failed(e.getCode(), e.getMessage());
//        } catch (Exception e) {
//            log.error(String.format("[后台]设置关于我们失败"), e);
//            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
//        }
//    }

//
//    @RequestMapping(value = "/uploadMainPicture", method = RequestMethod.POST)
//    @ApiOperation(tags = "管理台", httpMethod = "POST", value = "[前端]上传主图", response = String.class)
//    public ResponseWrapper uplaodMainPicture(@ApiJsonObject(name = "uploadMainPictureParams", value = {
//            @ApiJsonProperty(key = "file", value = "文件")
//    }) @RequestParam("file") MultipartFile file, HttpServletRequest request) {//1. 接受上传的文件  @RequestParam("file") MultipartFile file
//        try {
//            //2.根据时间戳创建新的文件名，这样即便是第二次上传相同名称的文件，也不会把第一次的文件覆盖了
//            String fileName = System.currentTimeMillis() + file.getOriginalFilename();
//            //3.通过req.getServletContext().getRealPath("") 获取当前项目的真实路径，然后拼接前面的文件名
////            String destFileName = req.getServletContext().getRealPath("") + "uploaded" + File.separator + fileName;
//
//            if(StaticVal.isWindows){
//                String path = "myimg" + File.separator + fileName;
//                String destFileName = File.listRoots()[0].getAbsolutePath() + path;
//                //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
//                File destFile = new File(destFileName);
//                destFile.getParentFile().mkdirs();
//                //5.把浏览器上传的文件复制到希望的位置
//                file.transferTo(destFile);
//                //6.把文件名放在model里，以便后续显示用
////            m.addAttribute("fileName", fileName);
////                String url = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + "/";
//                String filePath = StaticVal.FACK_ADD + "myimg/" + fileName;
//                log.info("文件访问路径 :{}", filePath);
//                return ResponseWrapper.succeed(filePath);
//            }else{
//                String path = "/myimg" + File.separator + fileName;
//                //4.第一次运行的时候，这个文件所在的目录往往是不存在的，这里需要创建一下目录（创建到了webapp下uploaded文件夹下）
//                File destFile = new File(path);
//                destFile.getParentFile().mkdirs();
//                //5.把浏览器上传的文件复制到希望的位置
//                file.transferTo(destFile);
//                //6.把文件名放在model里，以便后续显示用
////            m.addAttribute("fileName", fileName);
////                String url = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + "/";
//                String filePath = StaticVal.FACK_ADD + "myimg/" + fileName;
//                log.info("文件访问路径 :{}", filePath);
//                return ResponseWrapper.succeed(filePath);
//            }
//
//        } catch (FileNotFoundException e) {
//            log.error(String.format("[后台]上传主图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
//            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
////            return "上传失败," + e.getMessage();
//        } catch (IOException e) {
//            log.error(String.format("[后台]上传主图失败，参数:%s, 错误信息:%s", "", e.getMessage()));
//            return ResponseWrapper.failed(ErrorCodeEnum.FL500);
//        }
////        return "showImg";
//    }
